﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccess_Layer
{
    public static class PhanQuyenDAC
    {
        public static void them(PhanQuyen pqX)
        {
            DataAccessHelper.DB.PhanQuyens.InsertOnSubmit(pqX);
            DataAccessHelper.Save();
        }       

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="roleID"></param>
        /// <param name="quyen">0: xem, 1: chỉnh sửa</param>
        /// <returns></returns>
        public static PhanQuyen layPhanQuyen(string fileName, string roleID, int quyen)
        {
            var rs = DataAccessHelper.DB.PhanQuyens.Where(pq => pq.RoleID == new Guid(roleID) && pq.Trang == fileName && pq.Quyen == quyen).Select(pq => pq);
            return rs.Count() > 0 ? rs.First() : null;
        }

        public static void xoa(PhanQuyen pq)
        {
            DataAccessHelper.DB.PhanQuyens.DeleteOnSubmit(pq);
            DataAccessHelper.Save(); 
        }
        
        public static PhanQuyen layPhanQuyen(string pageName, string roleID)
        {
            var rs = DataAccessHelper.DB.PhanQuyens.Where(pq => pq.RoleID == new Guid(roleID) && pq.Trang == pageName).Select(pq => pq);
            return (rs.Count() == 0) ? null : rs.First();
        }
    }
}
